package com.kkb.billmngfeignclient.clients;

import com.github.pagehelper.PageInfo;
import com.kkb.springcloudbill.entity.Bill;
import com.kkb.springcloudbill.entity.BillType;
import com.kkb.springcloudbill.entity.ResultVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@FeignClient(value = "bill-mng-api", fallbackFactory = BillmngFeign.InitFallbackFactory.class)
public interface BillmngFeign {

    @GetMapping("/")
    @ResponseBody
    public ResponseEntity initPage(
            @RequestParam(required = false) Bill bill,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize);

    @GetMapping("/test")
    @ResponseBody
    public String test();

    @RequestMapping("/billtest")
    @ResponseBody
    public ResponseEntity<ResultVo> billtest(@RequestBody(required = false) Bill bill,
                                             @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);


    @RequestMapping("/billtest-nonbill")
    @ResponseBody
    public ResponseEntity<ResultVo> billsNonBill(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize);
    @GetMapping("/billtype")
    @ResponseBody
    List<BillType> getAllBillType();

    @RequestMapping("/bill/update/{billId}")
    ResponseEntity<Bill> getBillById(@PathVariable Integer billId);

    @RequestMapping(value = "/bill/update")
    ResponseEntity<Integer> updateBillById(@RequestBody Bill bill);

    @RequestMapping(value = "/bill/delete/{billId}")
    ResponseEntity<Integer> deleteBill(@PathVariable Integer billId);

    //执行insert新的bill信息
    @RequestMapping(value = "/bill/add")
    ResponseEntity<Integer> addNewBill(@RequestBody Bill bill);


//    static class FallBack implements BillmngFeign{
//
//        @Override
//        public ResponseEntity initPage(Object bill, Integer pageNum, Integer pageSize) {
//            return ResponseEntity.ok(null);
//        }
//    }

    @Component
    static class InitFallbackFactory implements FallbackFactory<BillmngFeign> {

        @Override
        public BillmngFeign create(Throwable cause) {
            cause.printStackTrace();
            return null;
        }
    }
}
